package org.jeecg.modules.wms.inorder.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import org.jeecg.common.api.vo.Result;

import org.jeecg.modules.wms.wmstask.entity.WmsTasks;
import org.jeecg.modules.wms.wmstask.entity.WmsTasksRecords;
import org.jeecg.modules.wms.wmstask.service.IWmsTasksRecordsService;
import org.jeecg.modules.wms.wmstask.service.IWmsTasksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/inorder/putawayTasks")
@RestController
public class putawayTasksController {
    @Autowired
    private IWmsTasksService wmsTasksService;
    @Autowired
    private IWmsTasksRecordsService wmsTasksRecordsService;


    @Operation(summary = "表-分页列表查询")
    @RequestMapping("/list")
    @GetMapping
    public Result<IPage<WmsTasks>> queryPageList(WmsTasks wmsTasks,
                                                 @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                 HttpServletRequest req) {
        Page<WmsTasks> page = new Page<WmsTasks>(pageNo, pageSize);


        IPage<WmsTasks> pageList = wmsTasksService.pagePlus(page, wmsTasks);
        return Result.OK(pageList);
    }

    @Operation(summary = "记录表-分页列表查询")
    @GetMapping(value = "/records")
    public Result<IPage<WmsTasksRecords>> queryPageList(WmsTasksRecords wmsTasksRecords,
                                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                        HttpServletRequest req) {
        Page<WmsTasksRecords> page = new Page<WmsTasksRecords>(pageNo, pageSize);
        IPage<WmsTasksRecords> pageList = wmsTasksRecordsService.pageLists(page, wmsTasksRecords);
        return Result.OK(pageList);
    }

    /**
     * 上架任务
     * @param records
     * @return
     */

    @RequestMapping("/addRecords")
    public Result<String> addRecords(@RequestBody WmsTasksRecords records) {
        String id = records.getId();
        records.setTaskId(id);
        records.setId(null);
        wmsTasksService.putAway(records);
        return Result.OK("添加成功！");
    }
}
